package org.xs.web.http;

import java.util.HashMap;
import java.util.Locale;
import java.util.Map;

import org.xs.web.http.i18n.Location;
import org.xs.web.http.velocity.AppContextMap;

 
public class XSContext{
	private Map<String, Object> context = new HashMap<String, Object>();
	private boolean isFreeze = false;
	private XSContext(){}
	
	private void freeze(){
		if(!isFreeze){
			//M is validate error message
			context.put("S", new AppContextMap());
			context.put("R", S.params());
			context.put("F", S.flash());
			context.put("L", Location.create().message());
			context.put("Identity", new Identity());
			context.put("Base", XSRules.ctxPath != null && XSRules.ctxPath.length() > 0 ? XSRules.ctxPath : "");
			isFreeze = true;
		}
	}
	
	public static XSContext create(){
		return new XSContext();
	}
	
	public Object get(Object key) {
		freeze();
		return context.get(key);
	}

}
